package com.caosy.grassthinkremote.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;

/**
 * 从文件中加载jks
 */
@Configuration
public class KeyStoreConfig {
    @Value("${jwt.password}")
    private String password;

    @Bean
    public KeyStore keyStore() throws Exception {
        KeyStore keyStore = KeyStore.getInstance("JKS");//创建一个JKS型的密钥库对象
        InputStream stream = getClass().getResourceAsStream("/myRSAKey.jks");//获取文件的字节流
        keyStore.load(stream,password.toCharArray());//将密钥load进入keyStore对象
        stream.close();

        return keyStore;
    }
}
